﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;
using Maticsoft.DBUtility;

public partial class UserControls_blockask : BaseUserControl
{
    // Fields
    protected int askcount = 0;
    protected List<Maticsoft.Model.Ask> asks = new List<Maticsoft.Model.Ask>();

    protected string kefumsn = string.Empty;
    protected string kefuqq = string.Empty;
    protected string sitename = string.Empty;
    protected string team_id = string.Empty;
    protected Maticsoft.Model.Team teammodel = null;

    // Methods
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!this.Page.User.Identity.IsAuthenticated)
        {
            this.pask.Visible = false;
            this.msg.Visible = false;
        }
        else
        {
            this.pask.Visible = true;
            this.msg.Visible = false;
        }
    }

    protected void submit_ServerClick(object sender, EventArgs e)
    {
        string errtext = string.Empty;
        int id = 0;
        if (base.AsUser == null)
        {
            errtext = "用户名失效,请重新登录！";
        }
        else if (this.teammodel != null)
        {
            id = this.teammodel.Id;
            int cityid = 0;
            if (base.CurrentCity != null)
            {
                cityid = base.CurrentCity.Id;
            }
            if ((this.consult_content.Value.IndexOf("<") != -1) || (this.consult_content.Value.IndexOf(">") != -1))
            {
                errtext = "不允许输入非法字符，提交失败!";
            }
            else
            {
                errtext = ActionHelper.User_SubmitAsk(this.teammodel.Id, base.AsUser.Id, cityid, this.consult_content.Value);
            }
        }
        else
        {
            errtext = "项目不能为空";
        }
        if (errtext == string.Empty)
        {
            this.pask.Visible = false;
            this.msg.Visible = true;
            base.SetSuccess("您的问题已成功提交，客服很快就会回复的，稍等一会儿再来看吧。");
            base.Response.Redirect(base.Request.Url.AbsoluteUri);
            base.Response.End();
        }
        else
        {
            base.SetError(errtext);
            base.Response.Redirect(base.Request.Url.AbsoluteUri);
            base.Response.End();
        }
    }

    public void UpdateView(Maticsoft.Model.Team team, bool show_all)
    {
        if (team != null)
        {
            this.team_id = team.Id.ToString();
        }
        string wherestr = "comment is not null ";
        if (team != null)
        {
            if (base.ASSystem != null)
            {
                this.kefumsn = base.ASSystem.Kefumsn;
                this.kefuqq = base.ASSystem.kefuqq;
                this.sitename = base.ASSystem.sitename;
            }
            if (!((base.ASSystem.Teamask != 0) || show_all))
            {
                wherestr = wherestr + " and team_id=" + this.team_id;
            }
        }
        Pagers pagers = DbHelperSQL.SelectByPager("*", wherestr, "Create_time desc", 1, 3, "ask", string.Empty, string.Empty);
        this.teammodel = team;
        this.askcount = pagers.TotalRecords;
        this.asks = new Maticsoft.BLL.Ask().DataTableToList(pagers.MyData);
    }

}